﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using EnvDTE;

namespace WizardExtension
{
    public class ExtensionBase
    {
        private string[] s_projectProperties = new string[] { "defaultnamespace" };

        protected void AddBaseNamespace(object automationObject, Dictionary<string, string> replacementsDictionary)
        {
            _DTE dte = automationObject as _DTE;
            Project project = (Project)((object[])dte.ActiveSolutionProjects)[0];
            foreach (Property prop in project.Properties)
            {
                if (s_projectProperties.Contains(prop.Name.ToLower()))
                    replacementsDictionary.Add("$" + prop.Name.ToLower() + "$", (prop.Value == null ? string.Empty : prop.Value.ToString()));
            }

            string baseNamespace = replacementsDictionary["$defaultnamespace$"];

            if (baseNamespace.Contains("."))
                baseNamespace = baseNamespace.Substring(0, baseNamespace.IndexOf("."));
            replacementsDictionary.Add("$basenamespace$", baseNamespace);
        }

        protected void ShowMessage(Dictionary<string, string> replacementsDictionary)
        {
            string message = string.Empty;
            foreach (string name in replacementsDictionary.Keys)
                message += name + " " + replacementsDictionary[name] + Environment.NewLine;

            MessageBox.Show(message);
        }
    }
}
